# coding = utf-8
# -*- coding:utf-8 -*-
import decimal
import os
from typing import List

import joblib
import numpy as np

model_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'model_with_scaler')


def detect(featuresList: List[List[int]], amountList: List[decimal.Decimal]) -> List[bool]:
    model_with_scaler = joblib.load(model_path)

    columns_features = np.array(featuresList)
    column_amount = np.array(amountList, dtype='float').reshape(-1, 1)
    column_amount = model_with_scaler['amount_scaler'].transform(column_amount)
    data = np.concatenate((columns_features, column_amount), axis=1)
    predictions = model_with_scaler['model'].predict(data)
    return [pred == 1 for pred in predictions.tolist()]


detect.vector = True

if __name__ == '__main__':
    ret = detect(
        [
            [-1.39598357648026, 1.07394393065875, 0.213508735697434, -1.00551307370986, 1.187300373936,
             -1.07111854041464, 0.753203638755905, 0.30971495602621, -0.983991867539784, -1.70071141514904,
             0.823426013946253, 0.755747784301563, 0.57208601947088, -0.493305378300063, -0.470447091684077,
             0.748161458746014, -0.0446257458090844, 1.15426779428755, -0.580978900127479, -0.04190738904369,
             0.313836892986802, 0.629705007512215, -0.702875042416293, -0.378664198371815, 1.17715716992152,
             -0.0670218758532906, -0.108995491056784, -0.0807276510778096],
            [-1.99458047217904, -1.63531939810522, 1.00669502032082, -1.43318273761075, 3.25919383016879,
             4.00823861971185, -1.66001967781548, 1.09946561236069, 1.91968533357403, -0.518543946411732,
             -1.05471184392788, 0.446539472296582, -0.468234843104227, -1.40433618221015, -1.8103263742068,
             -0.277012303056273, -0.290667580529318, -0.608743967003329, -0.218456639889371, -0.677311451910878,
             -0.258971403019176, 0.0809710102853903, -0.579907932919128, 0.830053981653551, -0.462078172323048,
             0.437226392974709, -0.170400933244463, 0.0175635565102101],
            [-3.0435406239976, -3.15730712090228, 1.08846277997285, 2.2886436183814, 1.35980512966107,
             -1.06482252298131, 0.325574266158614, -0.0677936531906277, -0.270952836226548, -0.838586564582682,
             -0.414575448285725, -0.503140859566824, 0.676501544635863, -1.69202893305906, 2.00063483909015,
             0.666779695901966, 0.599717413841732, 1.72532100745514, 0.283344830149495, 2.10233879259444,
             0.661695924845707, 0.435477208966341, 1.37596574254306, -0.293803152734021, 0.279798031841214,
             -0.145361714815161, -0.252773122530705, 0.0357642251788156],
            [-2.30334956758553, 1.759247460267, -0.359744743330052, 2.33024305053917, -0.821628328375422,
             -0.0757875706194599, 0.562319782266954, -0.399146578487216, -0.238253367661746, -1.52541162656194,
             2.03291215755072, -6.56012429505962, 0.0229373234890961, -1.47010153611197, -0.698826068579047,
             -2.28219382856251, -4.78183085597533, -2.61566494476124, -1.33444106667307, -0.430021867171611,
             -0.294166317554753, -0.932391057274991, 0.172726295799422, -0.0873295379700724, -0.156114264651172,
             -0.542627889040196, 0.0395659889264757, -0.153028796529788],
        ],
        [
            decimal.Decimal('2.35'),
            decimal.Decimal('17.6'),
            decimal.Decimal('529'),
            decimal.Decimal('239.93'),
        ]
    )

    print(ret)
